package com.mentaleye.dal.dao.mybatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mentaleye.dal.dao.RolePersonDao;
import com.mentaleye.dal.model.RolePerson;
import com.mentaleye.dal.model.RolePersonExample;
import com.mentaleye.dal.service.RolePersonMapper;
@Repository
public class RolePersonDaoImpl extends BaseDao implements RolePersonDao{

	@Autowired private RolePersonMapper rolePersonMapper;
	@Override
	public boolean insertPersonToRole(RolePerson rolePerson) {
		return getResultByInt(rolePersonMapper.insertSelective(rolePerson));
	}

	/**
	 * 通过人员id删除关联数据
	 */
	@Override
	public boolean deletePersonFromRole(Integer PersonId,Integer roleNo,Integer personType) {
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("personNo", PersonId);
		map.put("roleNo", roleNo);
		map.put("personType", personType);
		return getResultByInt(rolePersonMapper.deleteByMap(map));
	}

	/**
	 * 通过id集合来删除集合
	 */
	@Override
	public boolean deletePersonFromRoleByList(List<Integer> ids,Integer roleNo) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("list", ids);
		map.put("roleNo", roleNo);
		return getResultByInt(rolePersonMapper.deleteList(map));
	}

	/**
	 * 通过角色编号查询该 角色下的所有人员
	 */
	@Override
	public List<RolePerson> queryRolePersonListByRoleNo(Integer roleNo) {
		RolePersonExample rolePersonExample = new RolePersonExample();
		rolePersonExample.createCriteria().andRoleNoEqualTo(roleNo);
		return rolePersonMapper.selectByExample(rolePersonExample);
	}

	@Override
	public List<RolePerson> queryRolePerson(Map<String, Object> map) {
		return rolePersonMapper.selectRolePersonByMap(map);
	}

	@Override
	public boolean insertPersonToRoleList(List<RolePerson> list) {
		return getResultByInt(rolePersonMapper.insertList(list));
	}

}
